package com.arox.springinaction.web.controller;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.arox.springinaction.security.Message;
import com.arox.springinaction.security.MessageBoardService;

@Controller
@RequestMapping("/messageList*")
public class MessageListController {

    private MessageBoardService messageBoardService;

    @Autowired
    public MessageListController(final MessageBoardService messageBoardService) {
	this.messageBoardService = messageBoardService;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String generateList(Model model) {
	List<Message> messages = Collections.emptyList();
	messages = messageBoardService.listMessages();
	model.addAttribute("messages", messages);
	return "messageList";
    }

}
